﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Nuzzle.Managers
{
    public static class AdminManager
    {
        public static void ClientCommand(Network.GameClient client, string command)
        {
            var data = command.Split(' ').ToList();
            var header = data[0];
            data.RemoveAt(0);
            try
            {
                switch (header)
                {
                    case "infos":
                        var infos = new StringBuilder();
                        infos.Append("Nuzzle v" + Utilities.Basic.GetNuzzleVersion() + " by NightWolf<br />");
                        infos.Append("Players online : " + Network.GameServer.Clients.Count + "<br />");
                        client.ConsoleMessage(infos.ToString(), Protocol.Enums.ConsoleMessageTypeEnum.CONSOLE_INFO_MESSAGE);
                        break;

                    case "teleport":
                        var teleportedMap = MapManager.GetMap(int.Parse(data[0]));
                        if (teleportedMap != null)
                        {
                            client.Teleport(int.Parse(data[0]), int.Parse(data[1]));
                            client.ConsoleMessage("Teleported on map " + data[0], Protocol.Enums.ConsoleMessageTypeEnum.CONSOLE_INFO_MESSAGE);
                        }
                        else
                        {
                            client.ConsoleMessage("Map '" + data[0] + "'not found", Protocol.Enums.ConsoleMessageTypeEnum.CONSOLE_ERR_MESSAGE);
                        }
                        break;

                    default:
                        client.ConsoleMessage("Command '<b>" + header + "</b>' doesnt exist", Protocol.Enums.ConsoleMessageTypeEnum.CONSOLE_ERR_MESSAGE);
                        break;
                }
            }
            catch (Exception e)
            {
                client.ConsoleMessage("Unknown error : " + e.Message, Protocol.Enums.ConsoleMessageTypeEnum.CONSOLE_ERR_MESSAGE);
            }
        }
    }
}
